package cn.mw.cmdb.template.entity.export;

import cn.mw.cmdb.template.constant.MwTemplateConfigurationConstant;
import cn.mw.cmdb.template.enums.TriggerLevelEnum;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author gengjb
 * @description 触发器导出实体
 * @date 2024/9/3 15:52
 */
@Getter
@Setter
@Schema(name = "TriggerExportDto", description = "触发器导出实体")
public class TriggerExportDto {

    private String triggerid;

    @ExcelProperty(value = {"触发器名称"})
    private String description;

    @ExcelProperty(value = {"表达式"})
    private String expression;

    @ExcelProperty(value = {"严重性"})
    private String priority;

    @ExcelProperty(value = {"状态"})
    private String status;

    public void setStatus(String status) {
        if(StringUtils.isNotEmpty(status) && Integer.parseInt(status) == 0){
            this.status = MwTemplateConfigurationConstant.ENABLED;
            return;
        }
        if(StringUtils.isNotEmpty(status) && Integer.parseInt(status) == 1){
            this.status = MwTemplateConfigurationConstant.NOT_ENABLED;
            return;
        }
        this.status = status;
    }

    public void setPriority(String priority) {
        if(StringUtils.isNotEmpty(priority)){
            TriggerLevelEnum triggerLevelEnum = TriggerLevelEnum.getTriggerLevelEnum(priority);
            if(triggerLevelEnum != null){
                this.priority = triggerLevelEnum.getName();
                return;
            }
        }
        this.priority = priority;
    }
}
